import {ChangeDetectorRef, Component, forwardRef, Inject, Input, OnInit, } from '@angular/core';
import {NzMessageService} from 'ng-zorro-antd';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';


@Component({
    selector: 'base-input-range',
    templateUrl: './base-input-range.component.html',
    styleUrls: ['./base-input-range.component.less'],
    providers: [
        {
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => BaseInputRangeComponent),
            multi: true
        }
    ]
})

export class BaseInputRangeComponent implements OnInit, ControlValueAccessor {

    @Input()
    valueChange: (value: string | string[] | object) => any;
    changeFn = undefined;

    constructor(
        public message: NzMessageService,
        @Inject(ChangeDetectorRef) public readonly cd: ChangeDetectorRef) {
    }

    _value: string[] = ['', ''];

    get value() {
        return this._value;
    }

    set value(value: any) {
        this._value = value;
        if (this.changeFn) {
            this.changeFn(value);
        }
    }

    ngOnInit(): void {

    }


    registerOnChange(fn: any): void {
        this.changeFn = fn;
    }

    registerOnTouched(fn: any): void {
    }

    setDisabledState(isDisabled: boolean): void {

    }

    writeValue(_value: any): void {
        if (!_value) {
            return;
        }
        this._value = _value;
    }
}
